﻿<html xmlns="http://www.w3.org/1999/xhtml" class="hb-loaded">
 <head></head>
 <body>
  
  <link href="css/shopping.css?v=1.3.5" type="text/css" rel="stylesheet" />
  <script src="../js/jquery.js" type="text/javascript"></script>
  <script src="../js/shoppcart.js" type="text/javascript"></script>
  <title>购物车</title> 
  <iframe src="javascript:false;" style="display: none;"></iframe> 
  <form id="aspnetForm" action="/nCart/Cart.aspx" method="post" name="aspnetForm">
   <!--全部背景--> 
   <div class="all-thing"> 
    <!--中间内容--> 
    <div class="tcmain"> 
     <!--头部--> 
     <div class="shop_top"> 
      <div class="shopt_left fl"> 
       <a title="Darry Ring" href="../home/home.html"> <img width="186" height="42" src="../images/dr.png" /> </a>
       <span>求婚钻戒领导品牌</span> 
      </div> 
      <div class="shopt_right fr"> 
       <span id="ctl00_ltlUname"></span>
       <a class="my_dr" href="../member/myDr.html">我的DR</a>
       <a onClick="logout()" class="tc_dr" href="javascript:void(0)">退出</a>
       <a class="help_dr" href="../help.html">帮助中心</a>
      </div> 
     </div> 
     <!--头部end--> 
     <!--导航条--> 
     <div class="shop_nav" id="ctl00_showNav"></div> 
     <!--导航条end--> 
  
     <script type="text/javascript">
          let uName;
          let uId;
          $(function () {
           NameAndId();
           ShoppingCart();
           Shu();
           Nan()
          })


           function NameAndId() {
            $.ajaxSetup({async:false});
            $.getJSON("http://localhost:8080/DiamondRing/UserName",function (date) {
             uId=date.userId;
             uName=date.loginName;
             if (uName.length>0){
              $("#ctl00_ltlUname").html("您好!"+uName);
             }
            })
           }




      //删除商品
      function deleteCart(cid) {
        if (confirm("确认删除？")) {
            $.get("http://localhost:8080/DiamondRing/DeleteServlet" ,"date="+cid, function (date) {
               if (date>0){
                   alert("删除成功");
                   $("#"+cid).remove();
                   Zjie();
                    Shu();
                   window.location.reload();
               }else {
                   alert("删除失败");
               }

            });
        }
    }

      //清空购物车
      function clearCart() {
      alert(uId)
        if (confirm("确认清除？")) {
            $.get("http://localhost:8080/DiamondRing/EmptyServlet","date="+uId,function (date) {
             if (date>0){
              alert("清空成功");
              $(".cp_tr").remove();
              $("#price").html("0")
              Shu();
              window.location.reload();
             }else {
              alert("清空失败");
             }
            });
        }
    }

      function toPay() {
        var nu = '1';
        window.location = "trueloveAgreement.html";
    }

      //判断是否为数字，并且尺寸不能大于26
      function Nan() {
       $("body").delegate(".size","blur",function () {
        if (isNaN($(this).val())){
            alert("只能填数字");
            $(this).val("5");
        }else if ($(this).val()>26){
           alert("尺寸不能大于26");
           $(this).val("5");
        }else if ($(this).val()==""||$(this).val()==null){
           alert("尺寸不能为空")
           $(this).val("5");
        }else if ($(this).val()==0){
         alert("尺寸不能为0")
         $(this).val("5");
        }else if ($(this).val()<0){
          alert("尺寸不能为负数")
         $(this).val("5");
        }
       })
    }

      //总价格
      function Zjie() {
              var prices=document.getElementsByName("pirs");
              var sum=0;
              for(var i=0; i<prices.length;i++){
               sum+=parseInt(formatPrice2(prices[i].value));
              }
               document.getElementById("price").innerHTML=formatPrice(sum);
      }

      //为价格添加逗号
      function formatPrice(price) {
       return String(price).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      }

      //为价格去掉逗号
      function formatPrice2(price) {
       return String(price).replace(/[^0-9]*/g,"");
      }

      //修改尺寸和刻字
      function SizeLeetring(cartid) {
      var Size=$("#"+cartid+" .size").val()
      var Leetr=$("#"+cartid+" .Lettering").val()
           $.get("http://localhost:8080/DiamondRing/UpdateLettringServlet","size="+Size+"&lettering="+Leetr+"&id="+cartid,function (date) {
                      if (date>0){
                      }else {
                       alert("无效修改")
                      }
           })
      }

      //购物车信息
    function ShoppingCart(){
     $.getJSON("http://localhost:8080/DiamondRing/ShoppingServlet","userid="+uId,function (date) {
      var leetr;
          $.each(date,function () {
           if (this.lettering==null){
               leetr="";
           }else {
               leetr=this.lettering;
           }
                $("#qchu").append(" <tr class='cp_tr' id='"+this.cartId+"'>\n" +
                        "          <td class='sp_td'>\n" +
                        "           <a href='/darry_ring/87.html' class='jx_shop'>\n" +
                        "            <img width='85' height='85' src='../"+this.goods.goodsPath+"' />\n" +
                        "            <span>"+this.goods.series+'\t'+this.goods.style+"</span>\n" +
                        "           </a>\n" +
                        "          </td>\n" +
                        "          <td class='cz_td'>"+this.goods.texture+"</td> \n" +
                        "          <td class='sc_td'>\n" +
                        "            <input type='text' name='size'  class='size' value='"+this.size+"'  style=\"width: 20px;height: 20px\">\n" +
                        "          </td>\n" +
                        "          <td class=\"kz_td\">\n" +
                        "          <input type=\"text\" name=\"Lettering\" class=\"Lettering\" value=\""+leetr+"\" style=\"width: 70px;height: 20px\">\n" +
                        "          </td>\n" +
                        "          <td style=\"font-family:微软雅黑\" class=\"gm_td\">￥<input name='pirs' value='"+formatPrice(this.goods.diamondPrice)+"' disabled style='background-color:#fff9f8;border:none;height: 20px;width: 70px' ></td> \n" +
                        "          <td class=\"close_td\"><span onClick=\"deleteCart("+this.cartId+");\" class=\"sicon s_close\"></span><input type='button' value='修改' onClick=\"SizeLeetring("+this.cartId+");\"></td>\n" +
                        "         </tr>")
           Shu();
           Zjie();
          })

     })

    }

    //计算商品数量
    function Shu(){
     $("#shul").html($("#qchu").children().length-1)
    }
</script> 
     <!--内容--> 
     <div class="shop_cort"> 
      <!--左边--> 
      <div class="shop_cort-left fl"> 
       <h3>查看我的购物车</h3> 
       <!--购物车--> 
       <table cellspacing="0" cellpadding="0" border="0" class="shop_tabble"> 
        <tbody id="qchu">
         <tr class="nav_tr" >
          <td style="width:240px" class="sp_td">商品</td> 
          <td style="width:100px" class="cz_td">材质</td> 
          <td style="width:100px" class="sc_td">尺寸(可修改)</td>
          <td style="width:100px" class="kz_td">刻字(可修改)</td>
          <td class="gm_td">购买价</td> 
         </tr>
        </tbody>
       </table> 
       <!--购物车end--> 
       <!--结算--> 
       <div class="shop_js"> 
        <a class="jx_shop" href="../commodityQuery.html">继续购物</a>
        <a class="qk_shop" href="javascript:clearCart();">清空购物车</a> 
        <span>你购买了<i id="shul"></i>件商品</span>
        <span>总计：<i style="font-family:微软雅黑" class="fw_bold">￥<span id="price"></span></i></span>
        <span onClick="toPay();" class="end_bt"><em>立即结算</em></span> 
       </div> 
       <!--结算end--> 
      </div> 
      <!--左边end--> 
      <!--右边--> 
      <!--右边--> 
      <div class="shop_cort-right fr"> 
       <div class="shop_right-nr"> 
        <h3>购物帮助指南</h3> 
        <div class="shop_right-zx line_bottom"> 
         <p class="shop_lx">24小时在线客服</p> 
         <p class="shop_tel">400-01-13520</p> 
        </div> 
        <div class="shop_right-zf line_bottom"> 
         <h4>支付安全保障</h4> 
         <p>安全支付系统采用SSL加密。</p> 
         <ul class="shop_right-ul"> 
          <li class="shop_cor-yl"></li> 
          <li class="shop_cor-cft"></li> 
          <li class="shop_cor-zf"></li> 
         </ul> 
        </div> 
        <div class="shop_right-ps"> 
         <h4>全球配送</h4> 
         <p class="shop_kd">支持全球配送,店铺取货</p> 
         <p class="shop_bj">全程保价 无风险</p> 
        </div> 
       </div> 
      </div> 
      <!--右边end--> 
      <!--右边end--> 
     </div> 
     <!--底部--> 
     <div class="cmain shop_foot"> 
      <p>Copyright &copy; 2006-2015  戴瑞珠宝 All Rights Reserved. 粤ICP备XXX号</p> 
      <p>中国互联网违法信息举报中心 | 中国公安网络110报警服务 | 本网站提供所售商品的正式发票</p> 
      <div class="shop_foot-img"> 
       <img src="../home/image/db.jpg" />
      </div> 
     </div> 
     <!--底部end--> 
    </div> 
    <!--全部背景end--> 
   </div> 
   <script type="text/javascript">

        function logout() {
            if (window.confirm('确定退出吗？')) {
                $.get("http://localhost:8080/DiamondRing/OutServlet",function (data) {
                 if (data>0){
                    window.location.href = "http://localhost:8080/DiamondRing/home/home.html";
                 }

                });
            }
        }
</script> 
  </form> 
 
 </body>
</html>